-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added tests #975
Added tests #975
Conversation
WalkthroughThis pull request updates multiple Solidity facet test files and associated contract files. The changes expand the test coverage for various facets, including access control, refund handling, domain ID management, and DEX management. New test functions have been introduced to validate error conditions, ownership restrictions, and proper revert scenarios. The modifications also include updates to function selector arrays, new error type imports, and the addition of helper events. A new mock contract is provided to simulate external call failures. Changes
Suggested reviewers
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
test/solidity/Facets/DexManagerFacet.t.sol (1)
273-274
: Consider using unchecked block for gas optimization.The loop counters in these test functions could use unchecked blocks for gas optimization, similar to the pattern used in the existing test on line 128.
Apply this diff to optimize the loops:
- for (uint256 i = 0; i < 3; i++) { + for (uint256 i = 0; i < 3; ) { assertTrue(dexMgr.isFunctionApproved(signatures[i])); + unchecked { ++i; } } - for (uint256 i = 0; i < 3; i++) { + for (uint256 i = 0; i < 3; ) { assertFalse(dexMgr.isFunctionApproved(signatures[i])); + unchecked { ++i; } }Also applies to: 278-279
test/solidity/Facets/DeBridgeDlnFacet.t.sol (1)
411-430
: LGTM! Good low-level storage testing.The test effectively validates storage slot computation and access. Consider adding a comment explaining the storage layout pattern being tested.
Add a comment explaining the diamond storage pattern:
function test_getStorage() public { + // Test diamond storage pattern where each facet's storage is namespaced + // to avoid collisions with other facets' storage variables bytes32 namespace = keccak256("com.lifi.facets.debridgedln");test/solidity/Facets/AmarokFacetPacked.t.sol (1)
416-513
: LGTM! Comprehensive chain ID mapping tests.The test suite thoroughly covers chain ID mappings for all major chains and handles invalid cases. Consider refactoring to use parameterized testing for better maintainability.
Consider refactoring the chain-specific tests into a parameterized test:
struct ChainTestCase { string name; uint32 domainId; uint32 expectedChainId; } function test_getChainIdForDomain() public { ChainTestCase[] memory testCases = new ChainTestCase[](7); testCases[0] = ChainTestCase("ETH", 6648936, 1); testCases[1] = ChainTestCase("POL", 1886350457, 137); // ... add other cases for (uint i = 0; i < testCases.length; i++) { ChainTestCase memory tc = testCases[i]; uint32 result = amarokFacetPacked.getChainIdForDomain(tc.domainId); assertEq( result, tc.expectedChainId, string.concat(tc.name, " domainId should return correct chainId") ); } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
test/solidity/Facets/AccessManagerFacet.t.sol
(3 hunks)test/solidity/Facets/AcrossFacetPacked.t.sol
(2 hunks)test/solidity/Facets/AcrossFacetV3.t.sol
(2 hunks)test/solidity/Facets/AmarokFacetPacked.t.sol
(3 hunks)test/solidity/Facets/CBridge.t.sol
(4 hunks)test/solidity/Facets/CBridgeFacetPacked.t.sol
(2 hunks)test/solidity/Facets/DeBridgeDlnFacet.t.sol
(4 hunks)test/solidity/Facets/DexManagerFacet.t.sol
(5 hunks)test/solidity/utils/MockFailingContract.sol
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: enforce-min-test-coverage
- GitHub Check: run-unit-tests
🔇 Additional comments (18)
test/solidity/Facets/DexManagerFacet.t.sol (4)
9-9
: LGTM! Import statement added for error types.The import statement is correctly added to support the new authorization test cases.
50-56
: LGTM! Improved test accuracy with explicit caller context.The addition of
vm.startPrank/stopPrank
calls consistently ensures that all operations are performed with the correct owner context across all test cases.Also applies to: 60-67, 71-84, 88-105, 109-115, 119-135, 139-143, 147-151, 155-163, 167-175
178-246
: LGTM! Comprehensive authorization test coverage added.The new test cases thoroughly verify access control by:
- Testing all owner-restricted functions
- Verifying proper error handling for unauthorized access
- Including edge cases like self-authorization checks
248-283
: LGTM! Complete function approval lifecycle tests added.The new test cases properly verify:
- Both single and batch operations
- Both enabling and disabling of function approvals
- Proper state verification through assertions
test/solidity/utils/MockFailingContract.sol (1)
4-8
: LGTM! Well-designed mock contract.The contract is well-designed for testing failure scenarios with a clear, single responsibility.
test/solidity/Facets/AccessManagerFacet.t.sol (3)
25-30
: LGTM! Comprehensive setup of function selectors.The setup correctly includes both setCanExecute and addressCanExecuteMethod selectors.
75-82
: LGTM! Good test for self-authorization prevention.Test verifies that a contract cannot authorize itself, which is a critical security check.
84-156
: LGTM! Thorough test coverage for access control.Excellent set of test cases covering:
- Default access state
- Access granting
- Access revocation
- Different method selectors
- Different executors
test/solidity/Facets/CBridge.t.sol (3)
31-35
: LGTM! Well-structured event definition.The CBridgeRefund event properly indexes relevant parameters for efficient filtering.
206-227
: LGTM! Thorough success case testing.Test properly sets up the environment, mocks external calls, and verifies event emission.
229-285
: LGTM! Comprehensive error case coverage.Tests cover all critical error scenarios:
- Unauthorized caller
- Invalid call address
- External call failures
test/solidity/Facets/AcrossFacetV3.t.sol (1)
276-293
: LGTM! Good validation of information consistency.Test properly verifies that mismatched receiver addresses between bridgeData and validAcrossData are caught.
test/solidity/Facets/DeBridgeDlnFacet.t.sol (3)
34-37
: LGTM! Well-structured error and event declarations.The error and event declarations follow best practices with clear naming and proper parameter indexing.
44-57
: LGTM! Proper test setup initialization.The setUp function is correctly updated to include new function selectors for the deBridge chain ID management functionality.
349-394
: LGTM! Comprehensive test coverage for deBridge chain ID management.The test suite effectively covers:
- Setting and retrieving chain IDs
- Handling uninitialized facet errors
- Handling unknown chain ID errors
- Event emission verification
test/solidity/Facets/CBridgeFacetPacked.t.sol (1)
495-551
: LGTM! Thorough error handling tests for triggerRefund.The test suite comprehensively covers error scenarios:
- Unauthorized access control
- Invalid contract address validation
- External call failure handling
test/solidity/Facets/AmarokFacetPacked.t.sol (1)
50-76
: LGTM! Proper test setup for new functionality.The function selectors array is correctly updated to include the getChainIdForDomain selector.
test/solidity/Facets/AcrossFacetPacked.t.sol (1)
621-633
: LGTM! Good failure scenario testing.The test effectively validates the contract's behavior when a withdrawal operation fails using a mock contract.
Test Coverage ReportLine Coverage: 80.38% (2287 / 2845 lines) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (2)
test/solidity/Facets/AcrossFacetV3.t.sol (1)
276-293
: 🛠️ Refactor suggestionRename test function to follow the naming convention.
Based on the past review comments, the test name should follow the convention:
testRevert_willRevertWhen<Scenario>
. A better name would be:- function testRevert_InformationMismatch() public { + function testRevert_willRevertWhenReceiverAddressesMismatch() public {Also, consider adding a descriptive comment explaining the test scenario.
test/solidity/Facets/CBridge.t.sol (1)
206-227
: 🛠️ Refactor suggestionAdd balance checks to verify token transfers.
Based on past review comments, when testing token transfers, it's important to verify balance changes in the calling wallet.
Add balance checks before and after the refund:
function test_TriggerRefundSucceedsWhenCalledByOwner() public { address callTo = address(CBRIDGE_ROUTER); bytes memory callData = abi.encodeWithSignature("someFunction()"); address assetAddress = ADDRESS_USDT; address to = USER_RECEIVER; uint256 amount = 100 * 10 ** usdt.decimals(); deal(ADDRESS_USDT, address(cBridge), amount); + uint256 preRefundBalance = IERC20(assetAddress).balanceOf(to); vm.mockCall(callTo, callData, abi.encode(true)); vm.expectEmit(true, true, true, true, address(cBridge)); emit CBridgeRefund(assetAddress, to, amount); cBridge.triggerRefund( payable(callTo), callData, assetAddress, to, amount ); + + uint256 postRefundBalance = IERC20(assetAddress).balanceOf(to); + assertEq(postRefundBalance - preRefundBalance, amount, "Refund amount should be correct"); }
🧹 Nitpick comments (2)
test/solidity/Facets/CBridge.t.sol (1)
251-269
: Test name should be more specific about why the address is not allowed.Based on past review comments, test names should be specific to differentiate between various failing scenarios.
Rename the test to be more specific:
-function testRevert_TriggerRefundFailsWhenCallToAddressIsNotAllowed() +function testRevert_TriggerRefundFailsWhenCallToAddressIsNotInAllowList()test/solidity/Facets/CBridgeFacetPacked.t.sol (1)
517-535
: Test name should be consistent with CBridge.t.sol.For consistency, rename this test to match the suggested name in CBridge.t.sol.
Rename the test:
-function testRevert_TriggerRefundFailsWhenCallToAddressIsNotAllowed() +function testRevert_TriggerRefundFailsWhenCallToAddressIsNotInAllowList()
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
test/solidity/Facets/AccessManagerFacet.t.sol
(5 hunks)test/solidity/Facets/AcrossFacetPacked.t.sol
(2 hunks)test/solidity/Facets/AcrossFacetV3.t.sol
(2 hunks)test/solidity/Facets/AmarokFacetPacked.t.sol
(3 hunks)test/solidity/Facets/CBridge.t.sol
(4 hunks)test/solidity/Facets/CBridgeFacetPacked.t.sol
(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- test/solidity/Facets/AcrossFacetPacked.t.sol
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: enforce-min-test-coverage
- GitHub Check: run-unit-tests
- GitHub Check: generate-tag
🔇 Additional comments (15)
test/solidity/Facets/AcrossFacetV3.t.sol (1)
9-9
: LGTM!The import statement is correctly placed and necessary for the new test function.
test/solidity/Facets/AccessManagerFacet.t.sol (4)
5-5
: LGTM!The import statement correctly includes the new
CannotAuthoriseSelf
error type used in the tests.
25-34
: LGTM!The setup correctly initializes the test environment by:
- Adding access manager function selectors including the new
addressCanExecuteMethod
- Adding restricted contract function selectors
81-81
: Add blank line after expectRevert.For consistency with the codebase style, add a blank line between
expectRevert
and the actual call.
78-166
: Add test for owner/admin access control.While the new tests provide good coverage for access control scenarios, there's still a missing test to verify that only admin/contract owner can call the
setCanExecute
function.Would you like me to help generate the missing test case?
test/solidity/Facets/AmarokFacetPacked.t.sol (3)
50-76
: LGTM! Function selector array updated correctly.The functionSelectors array is properly expanded to include the new
getChainIdForDomain
selector.
416-471
: Consider enhancing test coverage with edge cases.While the table-driven test approach is good, consider adding:
- Edge cases (e.g., uint32.max)
- Boundary values
You could write a helper function to reduce code duplication in the test cases:
+ function assertDomainChainMapping( + uint32 domainId, + uint32 expectedChainId, + string memory description + ) internal { + uint32 result = amarokFacetPacked.getChainIdForDomain(domainId); + assertEq(result, expectedChainId, description); + } function test_getChainIdForValidDomains() public { - DomainChainTestCase[] memory testCases = new DomainChainTestCase[](7); - testCases[0] = DomainChainTestCase({ - domainId: 6648936, - expectedChainId: 1, - description: "ETH domainId should return chainId 1" - }); - // ... more test cases ... - - for (uint256 i = 0; i < testCases.length; i++) { - uint32 result = amarokFacetPacked.getChainIdForDomain( - testCases[i].domainId - ); - - assertEq( - result, - testCases[i].expectedChainId, - testCases[i].description - ); - } + assertDomainChainMapping(6648936, 1, "ETH domainId should return chainId 1"); + assertDomainChainMapping(1886350457, 137, "POL domainId should return chainId 137"); + // ... more assertions ... }
481-481
: LGTM! Test function name updated to follow Foundry's convention.The renaming aligns with Foundry's test naming convention while preserving the test logic.
test/solidity/Facets/CBridge.t.sol (4)
7-7
: LGTM!The import of error types is appropriate for testing ownership, contract calls, and external call failures.
31-35
: LGTM!The event is well-structured with appropriate parameter indexing.
229-249
: LGTM!The test properly verifies that only the owner can call triggerRefund.
271-287
: LGTM!The test properly verifies the handling of external call failures.
test/solidity/Facets/CBridgeFacetPacked.t.sol (3)
10-10
: LGTM!The import is used consistently with CBridge.t.sol.
495-515
: LGTM!The test properly verifies ownership checks for the standAlone instance.
537-553
: LGTM!The test properly verifies external call failure handling for the standAlone instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (1)
test/solidity/Facets/CBridge.t.sol (1)
206-227
: 🛠️ Refactor suggestionAdd balance checks to verify token transfer.
The test should verify the token balances before and after the refund operation to ensure the transfer was successful.
function test_TriggerRefundSucceedsWhenCalledByOwner() public { address callTo = address(CBRIDGE_ROUTER); bytes memory callData = abi.encodeWithSignature("someFunction()"); address assetAddress = ADDRESS_USDT; address to = USER_RECEIVER; uint256 amount = 100 * 10 ** usdt.decimals(); deal(ADDRESS_USDT, address(cBridge), amount); + uint256 initialBalance = IERC20(assetAddress).balanceOf(to); + uint256 initialContractBalance = IERC20(assetAddress).balanceOf(address(cBridge)); vm.mockCall(callTo, callData, abi.encode(true)); vm.expectEmit(true, true, true, true, address(cBridge)); emit CBridgeRefund(assetAddress, to, amount); cBridge.triggerRefund( payable(callTo), callData, assetAddress, to, amount ); + + assertEq( + IERC20(assetAddress).balanceOf(to), + initialBalance + amount, + "Recipient balance should increase by refund amount" + ); + assertEq( + IERC20(assetAddress).balanceOf(address(cBridge)), + initialContractBalance - amount, + "Contract balance should decrease by refund amount" + ); }
🧹 Nitpick comments (1)
test/solidity/Facets/CBridge.t.sol (1)
271-289
: Enhance mock call setup for failure test.The test should explicitly mock the call to return false or revert to better simulate the failure scenario.
function testRevert_TriggerRefundFailsWhenCallToCBridgeRouterFails() public { address callTo = CBRIDGE_ROUTER; bytes memory callData = abi.encodeWithSignature("someFunction()"); address assetAddress = ADDRESS_USDT; address to = USER_RECEIVER; uint256 amount = 100 * 10 ** usdt.decimals(); + vm.mockCall( + callTo, + callData, + abi.encode(false) // Simulate failure by returning false + ); + vm.expectRevert(ExternalCallFailed.selector); cBridge.triggerRefund( payable(callTo), callData, assetAddress, to, amount ); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
test/solidity/Facets/AccessManagerFacet.t.sol
(4 hunks)test/solidity/Facets/CBridge.t.sol
(4 hunks)test/solidity/Facets/CBridgeFacetPacked.t.sol
(2 hunks)test/solidity/Facets/DexManagerFacet.t.sol
(5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- test/solidity/Facets/CBridgeFacetPacked.t.sol
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: enforce-min-test-coverage
- GitHub Check: run-unit-tests
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: generate-tag
🔇 Additional comments (6)
test/solidity/Facets/AccessManagerFacet.t.sol (4)
25-34
: LGTM! Good test setup with proper initialization of function selectors.The setup properly initializes both the access manager and restricted function selectors, providing a solid foundation for testing.
87-99
: LGTM! Good test for self-authorization prevention.The test properly verifies that a contract cannot authorize itself, which is a critical security check.
115-122
: LGTM! Comprehensive access control tests.The tests thoroughly verify:
- Default access state
- Access granting functionality
- Access checking functionality
Also applies to: 124-141
168-189
: LGTM! Good edge case coverage.The tests properly verify behavior with:
- Different method selectors
- Different executor addresses
Also applies to: 191-208
test/solidity/Facets/DexManagerFacet.t.sol (2)
196-208
: LGTM! Good test for preventing self-authorization in batch operations.The test properly verifies that a contract cannot authorize itself even in batch operations.
255-267
: LGTM! Comprehensive tests for function signature management.The tests thoroughly verify:
- Signature removal functionality
- Batch signature operations
- State verification after operations
Also applies to: 269-290
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
test/solidity/Facets/AmarokFacetPacked.t.sol (1)
416-476
: Consider parameterizing test cases to improve maintainability.The test cases for domain-to-chain ID mapping could be refactored to avoid duplicate code structure, as suggested in previous reviews.
Consider this approach:
- function test_getChainIdForValidDomains() public { - DomainChainTestCase[] memory testCases = new DomainChainTestCase[](8); - testCases[0] = DomainChainTestCase({ - domainId: 6648936, - expectedChainId: 1, - description: "ETH domainId should return chainId 1" - }); - // ... more test cases ... - for (uint256 i = 0; i < testCases.length; i++) { - uint32 result = amarokFacetPacked.getChainIdForDomain( - testCases[i].domainId - ); - assertEq( - result, - testCases[i].expectedChainId, - testCases[i].description - ); - } - } + function _assertDomainChainMapping( + uint32 domainId, + uint32 expectedChainId, + string memory description + ) internal { + uint32 result = amarokFacetPacked.getChainIdForDomain(domainId); + assertEq(result, expectedChainId, description); + } + + function test_getChainIdForValidDomains() public { + _assertDomainChainMapping(6648936, 1, "ETH domainId should return chainId 1"); + _assertDomainChainMapping(1886350457, 137, "POL domainId should return chainId 137"); + _assertDomainChainMapping(6450786, 56, "BSC domainId should return chainId 56"); + _assertDomainChainMapping(1869640809, 10, "OPT domainId should return chainId 10"); + _assertDomainChainMapping(6778479, 100, "GNO domainId should return chainId 100"); + _assertDomainChainMapping(1634886255, 42161, "ARB domainId should return chainId 42161"); + _assertDomainChainMapping(1818848877, 59144, "LIN domainId should return chainId 59144"); + _assertDomainChainMapping(9999999, 0, "Unknown domainId should return 0"); + }test/solidity/Facets/AccessManagerFacet.t.sol (1)
87-208
: Great addition of comprehensive test coverage!The new test functions thoroughly cover various access control scenarios including:
- Self-authorization prevention
- Owner-only access
- Default access state
- Access granting/revocation
- Different method selectors and executors
Consider adding additional assertions for completeness.
Some test functions could benefit from additional assertions to verify the complete state. For example:
function test_CanCheckGrantedAccess() public { vm.startPrank(USER_DIAMOND_OWNER); accessMgr.setCanExecute( RestrictedContract.restrictedMethod.selector, address(0xb33f), true ); bool canExecute = accessMgr.addressCanExecuteMethod( RestrictedContract.restrictedMethod.selector, address(0xb33f) ); assertEq(canExecute, true, "Access should be granted"); + // Verify the actual method execution succeeds + vm.prank(address(0xb33f)); + bool result = restricted.restrictedMethod(); + assertEq(result, true, "Method execution should succeed"); vm.stopPrank(); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
test/solidity/Facets/AccessManagerFacet.t.sol
(4 hunks)test/solidity/Facets/AmarokFacetPacked.t.sol
(3 hunks)test/solidity/Facets/DeBridgeDlnFacet.t.sol
(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: enforce-min-test-coverage
- GitHub Check: run-unit-tests
- GitHub Check: generate-tag
🔇 Additional comments (16)
test/solidity/Facets/AmarokFacetPacked.t.sol (2)
50-76
: LGTM! Function selector array updated correctly.The functionSelectors array has been properly expanded to include the new
getChainIdForDomain
selector, maintaining the contract's functionality.
478-478
: LGTM! Function name updated to match naming convention.The test function has been renamed from
test_revert_cannotUseRelayerFeeAboveUint128Max_ERC20
totestRevert_cannotUseRelayerFeeAboveUint128Max_ERC20
to maintain consistency with the project's naming conventions.test/solidity/Facets/AccessManagerFacet.t.sol (3)
5-5
: LGTM!The new error imports align with the test functions being added.
25-34
: LGTM!The setup changes improve organization by clearly separating allowed and restricted function selectors.
43-85
: LGTM!The changes improve test readability by:
- Adding blank lines after
expectRevert
- Making pranking explicit with
startPrank
/stopPrank
These changes align with the team's established testing practices.
test/solidity/Facets/DeBridgeDlnFacet.t.sol (11)
8-8
: No issues with the new import.
The import reference forNotInitialized
appears correct and consistent with the usage in this file.
34-34
: New error declaration looks good.
IntroducingUnknownDeBridgeChain
aligns with the other custom errors declared in this contract.
36-37
: Event definition is appropriate and consistent.
Using an indexed parameter forchainId
helps with on-chain filtering and is generally recommended.
44-44
: Array resizing for function selectors is correct.
Expanding the array to accommodate additional selectors is properly handled and avoids out-of-bounds errors.
55-57
: Selector assignments are valid.
Assigning new selectors at indices 4, 5, and 6 matches the updated array size of 7, ensuring no indexing issues.
348-363
: Functional test to confirm setting and retrieving a chain ID.
The test rigorously checks event emission and ensures the correct mapping is stored. Excellent coverage.
365-377
: Revert test confirms non-initialized facet behavior.
This test properly verifies theNotInitialized
error scenario, ensuring defensive programming is enforced.
379-388
: Basic retrieval test is clear and thorough.
Verifies a straightforward set-and-get workflow for deBridge chain IDs. Looks solid.
390-396
: Unknown chain ID revert handling is verified properly.
This negative test scenario covers the expected error path and ensures robust error reporting.
398-411
: Empty receiver revert test is well-defined.
Ensures the contract correctly handles cases where thereceiver
field is an empty byte array.
413-432
: Storage slot verification is thorough.
Confirming the correct storage layout by computing and setting the slot helps prevent regressions or collisions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
test/solidity/Facets/CBridgeFacetPacked.t.sol (1)
601-623
: Fix typo in function name.The function name contains a typo: "Diffrent" should be "Different".
- function testRevert_TriggerRefundFailsWhenTryingToCallDiffrentContractThanCBridgeRouter() + function testRevert_TriggerRefundFailsWhenTryingToCallDifferentContractThanCBridgeRouter()test/solidity/Facets/CBridge.t.sol (2)
306-306
: Fix typo in function name."Diffrent" should be "Different" in the function name.
- function testRevert_TriggerRefundFailsWhenTryingToCallDiffrentContractThanCBridgeRouter() + function testRevert_TriggerRefundFailsWhenTryingToCallDifferentContractThanCBridgeRouter()
212-214
: Use descriptive mock function name.The mock function name "someFunction()" is not descriptive of what it's simulating. Consider using a more specific name that reflects the actual CBridge refund functionality being tested.
- bytes memory callData = abi.encodeWithSignature("someFunction()"); + bytes memory callData = abi.encodeWithSignature("withdrawRefund(uint256,address)");Also applies to: 251-253, 287-289, 311-313, 335-337
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
test/solidity/Facets/CBridge.t.sol
(4 hunks)test/solidity/Facets/CBridgeFacetPacked.t.sol
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: enforce-min-test-coverage
- GitHub Check: run-unit-tests
- GitHub Check: generate-tag
🔇 Additional comments (9)
test/solidity/Facets/CBridgeFacetPacked.t.sol (6)
10-10
: LGTM!The import statement correctly brings in the necessary error types used in the test cases.
50-54
: LGTM!The event declaration follows best practices with indexed parameters and clear naming.
501-538
: LGTM!The test case thoroughly validates the success scenario with an explicit receiver, including balance changes and event emissions.
540-577
: LGTM!The test case properly validates the success scenario without an explicit receiver, defaulting to the owner address.
579-599
: LGTM!The test case correctly verifies that non-owners cannot trigger refunds.
625-647
: LGTM!The test case properly validates the handling of external call failures.
test/solidity/Facets/CBridge.t.sol (3)
4-7
: LGTM!The new imports and event declaration are well-organized and follow standard conventions.
Also applies to: 31-35
81-89
: LGTM!The function selectors array is correctly updated to include the new
triggerRefund
selector.
330-352
: Add balance checks to failure test cases.Based on past review comments, it's good practice to verify balance changes even in failure scenarios to ensure no state changes occur.
Add the
assertBalanceChange
modifier to failure test cases:function testRevert_TriggerRefundFailsWhenCallToCBridgeRouterFails() public + assertBalanceChange(ADDRESS_USDT, USER_RECEIVER, 0) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
test/solidity/Facets/DexManagerFacet.t.sol (2)
293-295
: Optimize loop using unchecked increment.The loop counter can safely use unchecked increment since the loop has a fixed size of 3 iterations.
Apply this diff to optimize the loop:
- for (uint256 i = 0; i < 3; i++) { + for (uint256 i = 0; i < 3;) { assertTrue(dexMgr.isFunctionApproved(signatures[i])); + unchecked { ++i; } }
216-227
: Improve test structure by combining vm.prank and vm.expectRevert.The test structure can be improved by placing
vm.expectRevert
beforevm.prank
to make the test flow clearer.Apply this diff to improve the test structure:
function testRevert_FailToRemoveDexFromNotOwner() public { vm.prank(USER_DIAMOND_OWNER); dexMgr.addDex(address(c1)); vm.stopPrank(); - vm.expectRevert(UnAuthorized.selector); - vm.prank(NOT_DIAMOND_OWNER); + vm.expectRevert(UnAuthorized.selector); dexMgr.removeDex(address(c1)); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
test/solidity/Facets/AcrossFacetPacked.t.sol
(2 hunks)test/solidity/Facets/AcrossFacetV3.t.sol
(2 hunks)test/solidity/Facets/DexManagerFacet.t.sol
(5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- test/solidity/Facets/AcrossFacetPacked.t.sol
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: run-unit-tests
- GitHub Check: enforce-min-test-coverage
- GitHub Check: generate-tag
🔇 Additional comments (3)
test/solidity/Facets/DexManagerFacet.t.sol (1)
50-58
: Improve test naming convention for better readability.The test function names should follow a consistent pattern that clearly describes the test scenario. Consider renaming functions to follow the pattern:
test[Revert]_WillDoSomethingWhenSomethingHappens
.Apply this naming convention to the test functions:
- function test_CanAddDEX() public { + function test_WillAddDexWhenCalledByOwner() public { - function test_CanRemoveDEX() public { + function test_WillRemoveDexWhenCalledByOwner() public { - function test_CanBatchAddDEXs() public { + function test_WillBatchAddDexesWhenCalledByOwner() public { - function test_CanBatchRemoveDEXs() public { + function test_WillBatchRemoveDexesWhenCalledByOwner() public { - function test_CanApproveFunctionSignature() public { + function test_WillApproveFunctionSignatureWhenCalledByOwner() public { - function test_CanApproveBatchFunctionSignature() public { + function test_WillApproveBatchFunctionSignatureWhenCalledByOwner() public { - function testFail_AddZeroAddress() public { + function testRevert_WillRevertWhenAddingZeroAddress() public { - function testFail_AddNonContract() public { + function testRevert_WillRevertWhenAddingNonContract() public { - function testFail_BatchAddZeroAddress() public { + function testRevert_WillRevertWhenBatchAddingZeroAddress() public { - function testFail_BatchAddNonContract() public { + function testRevert_WillRevertWhenBatchAddingNonContract() public {Also applies to: 60-69, 71-86, 88-107, 109-117, 119-137, 139-145, 147-153, 155-165, 167-177, 179-187, 189-200, 202-214, 216-227, 229-241, 243-252, 254-266, 268-280, 282-303
test/solidity/Facets/AcrossFacetV3.t.sol (2)
125-169
: Improve test naming convention and magic numbers.The test function names should follow a consistent pattern, and magic numbers should be replaced with named constants.
Apply these improvements:
- function test_canSwapAndBridgeTokensWithOutputAmountPercent() public { + function test_WillSwapAndBridgeTokensWithOutputAmountPercent() public { + // Define constants for percentages + uint64 private constant OUTPUT_AMOUNT_PERCENT_85 = 850000000000000000; // 85.00% + uint64 private constant OUTPUT_AMOUNT_PERCENT_93_75 = 937500000000000000; // 93.75% // In the test function - validAcrossData.outputAmountPercent = uint64(850000000000000000); // 85.00% + validAcrossData.outputAmountPercent = OUTPUT_AMOUNT_PERCENT_85; - function test_canSwapAndBridgeNativeTokensWithOutputAmountPercent() public { + function test_WillSwapAndBridgeNativeTokensWithOutputAmountPercent() public { - function testFailsToBridgeERC20TokensDueToQuoteTimeout() public { + function testRevert_WillRevertWhenBridgingERC20TokensWithExpiredQuote() public { - function test_contractIsSetUpCorrectly() public { + function test_WillSetUpContractWithCorrectValues() public { - function testRevert_RevertIfReceiverAddressesDontMatch() public { + function testRevert_WillRevertWhenReceiverAddressesDontMatch() public {Also applies to: 171-251, 253-264, 266-274, 276-294
276-294
: LGTM! The new test case improves coverage.The test case correctly verifies that the receiver addresses must match between
bridgeData
andvalidAcrossData
. The test structure follows best practices with proper setup, expectations, and cleanup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
test/solidity/Facets/AccessManagerFacet.t.sol (1)
87-208
: LGTM! Comprehensive test coverage for access control scenarios.The new test functions:
- Cover all critical access control paths
- Follow consistent patterns and naming conventions
- Improve overall test coverage as per PR objectives
One suggestion to consider: Add test cases for edge cases such as:
- Setting access for address(0)
- Setting access for multiple methods in a single transaction
test/solidity/Facets/DeBridgeDlnFacet.t.sol (2)
365-377
: Consider adding more edge cases to the initialization test.While the test correctly verifies the
NotInitialized
error case, consider adding tests for:
- Attempting to set chain ID with value 0
- Attempting to set deBridge chain ID with value 0
function testRevert_FailsToSetDeBridgeChainIdIfNotInitialized() public { vm.startPrank(address(0)); TestDeBridgeDlnFacet uninitializedFacet = new TestDeBridgeDlnFacet( DLN_SOURCE ); vm.expectRevert(NotInitialized.selector); uninitializedFacet.setDeBridgeChainId(137, 1001); + // Test with chain ID 0 + vm.expectRevert(NotInitialized.selector); + uninitializedFacet.setDeBridgeChainId(0, 1001); + + // Test with deBridge chain ID 0 + vm.expectRevert(NotInitialized.selector); + uninitializedFacet.setDeBridgeChainId(137, 0); + vm.stopPrank(); }
423-442
: Consider adding boundary tests for storage.The storage test is well-implemented but could benefit from additional edge cases:
- Test with maximum uint256 value
- Test with zero value
function test_GetStorage() public { bytes32 namespace = keccak256("com.lifi.facets.debridgedln"); uint256 chainIdKey = 1; uint256 expectedValue = 42; // compute the correct storage slot for `deBridgeChainId[chainIdKey]` bytes32 storageSlot = keccak256(abi.encode(chainIdKey, namespace)); // store the test value in the computed slot vm.store( address(deBridgeDlnFacet), storageSlot, bytes32(expectedValue) ); uint256 storedValue = deBridgeDlnFacet.getDeBridgeChainId(chainIdKey); assertEq(storedValue, expectedValue); + + // Test with maximum uint256 value + uint256 maxValue = type(uint256).max; + vm.store( + address(deBridgeDlnFacet), + storageSlot, + bytes32(maxValue) + ); + storedValue = deBridgeDlnFacet.getDeBridgeChainId(chainIdKey); + assertEq(storedValue, maxValue); + + // Test with zero value + vm.store( + address(deBridgeDlnFacet), + storageSlot, + bytes32(uint256(0)) + ); + storedValue = deBridgeDlnFacet.getDeBridgeChainId(chainIdKey); + assertEq(storedValue, 0); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
test/solidity/Facets/AccessManagerFacet.t.sol
(4 hunks)test/solidity/Facets/DeBridgeDlnFacet.t.sol
(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: enforce-min-test-coverage
- GitHub Check: run-unit-tests
- GitHub Check: generate-tag
🔇 Additional comments (8)
test/solidity/Facets/AccessManagerFacet.t.sol (3)
5-5
: LGTM! Import changes align with new test cases.The additional error imports support the new test cases for unauthorized access and self-authorization scenarios.
25-34
: LGTM! Well-structured initialization of function selectors.The separation of allowed and restricted function selectors improves code organization and clarity.
43-85
: LGTM! Test functions follow consistent patterns and incorporate previous feedback.The modifications align with past review comments by:
- Adding blank lines after expectRevert
- Using explicit pranking with start/stop blocks
test/solidity/Facets/DeBridgeDlnFacet.t.sol (5)
8-8
: LGTM! Good practice importing the error from a shared location.The import of
NotInitialized
from a shared error file promotes code reuse and consistency.
34-34
: LGTM! Well-structured error and event definitions.The error and event definitions follow Solidity best practices:
- Error name is descriptive and follows the naming convention
- Event includes indexed parameter for efficient filtering
Also applies to: 36-37
44-57
: LGTM! Comprehensive function selector setup.The setUp function properly initializes all required function selectors for the facet, including the new
setDeBridgeChainId
andgetDeBridgeChainId
selectors.
349-363
: LGTM! Well-structured test for setDeBridgeChainId.The test follows best practices:
- Tests both the event emission and state change
- Uses clear, descriptive variable names
- Includes proper assertions
1-443
:❓ Verification inconclusive
Consider improving branch coverage.
The current branch coverage is 45.16%, which is relatively low. Consider adding more test cases to cover:
- Error conditions in
startBridgeTokensViaDeBridgeDln
- Edge cases in
swapAndStartBridgeTokensViaDeBridgeDln
Let's analyze the current test coverage:
🏁 Script executed:
#!/bin/bash # Description: Find untested branches in the DeBridgeDlnFacet contract # Search for conditional statements in the contract ast-grep --pattern 'if ($condition) { $$$ }' # Search for require statements ast-grep --pattern 'require($condition, $message)'Length of output: 101
Action Required: Expand Tests to Boost Branch Coverage
The current tests in
test/solidity/Facets/DeBridgeDlnFacet.t.sol
exercise basic functionality, but branch coverage remains low (~45.16%). Although our AST grep commands didn’t reveal additional conditionals, a manual review suggests that some edge cases may not be exercised. In particular, consider adding tests to more fully cover:
Error scenarios in
startBridgeTokensViaDeBridgeDln
Ensure tests trigger failure modes such as invalid or empty receiver addresses and uninitialized states.Edge cases in
swapAndStartBridgeTokensViaDeBridgeDln
Include tests for parameter variations (e.g., handling insufficient amounts or unexpected swap outcomes) that explore all logical branches.Please verify that all conditional branches, both in the error paths and nominal flows of these functions, receive adequate testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (4)
test/solidity/Facets/DeBridgeDlnFacet.t.sol (1)
411-459
: Consider adding edge cases to error handling tests.While the error handling tests cover the basic scenarios, consider adding tests for:
- Setting chain ID to zero
- Setting the same chain ID multiple times
- Setting chain ID with max uint256 values
Example test case:
+ function testRevert_FailsIfAttemptingToSetZeroChainId() public { + vm.startPrank(USER_DIAMOND_OWNER); + + uint256 chainId = 137; + uint256 deBridgeChainId = 0; + + vm.expectRevert("ZeroChainId"); + + deBridgeDlnFacet.setDeBridgeChainId(chainId, deBridgeChainId); + + vm.stopPrank(); + }test/solidity/Facets/DexManagerFacet.t.sol (3)
9-9
: Add documentation for error types and constants.Consider adding NatSpec comments to document:
- The purpose of imported error types
- The significance of the NOT_DIAMOND_OWNER constant
+/// @notice Error types for authorization and validation checks import { CannotAuthoriseSelf, UnAuthorized, InvalidContract } from "src/Errors/GenericErrors.sol"; +/// @notice Address used for negative test cases, representing a non-owner account address internal constant NOT_DIAMOND_OWNER = address(0xabc123456);Also applies to: 16-16
303-305
: Use unchecked block for loop counter.For consistency with other loops in the file (e.g., lines 129-134), consider using an unchecked block for the loop counter increment.
- for (uint256 i = 0; i < 3; i++) { - assertTrue(dexMgr.isFunctionApproved(signatures[i])); - } + for (uint256 i = 0; i < 3; ) { + assertTrue(dexMgr.isFunctionApproved(signatures[i])); + unchecked { + ++i; + } + }
233-237
: Maintain consistent ordering of vm.expectRevert and vm.prank calls.For consistency with other test functions, consider moving vm.prank before vm.expectRevert.
- vm.expectRevert(UnAuthorized.selector); - - vm.prank(NOT_DIAMOND_OWNER); + vm.prank(NOT_DIAMOND_OWNER); + + vm.expectRevert(UnAuthorized.selector); + dexMgr.removeDex(address(c1));
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
test/solidity/Facets/DeBridgeDlnFacet.t.sol
(4 hunks)test/solidity/Facets/DexManagerFacet.t.sol
(5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: enforce-min-test-coverage
- GitHub Check: run-unit-tests
- GitHub Check: generate-tag
🔇 Additional comments (5)
test/solidity/Facets/DeBridgeDlnFacet.t.sol (4)
8-37
: LGTM! Well-structured error and event declarations.The new imports, error types, and event declarations are well-organized and follow Solidity best practices.
44-57
: LGTM! Comprehensive function selector initialization.The setUp function is properly updated to include new function selectors for chain ID management.
349-409
: LGTM! Thorough chain ID management test coverage.The test functions for chain ID management are comprehensive, covering:
- Setting chain ID as owner
- Verifying access control
- Getting chain ID
- Proper event emission
440-459
: LGTM! Comprehensive storage test.The storage test is well-implemented, validating the correct storage slot computation and value retrieval.
test/solidity/Facets/DexManagerFacet.t.sol (1)
1-314
: Well-structured test suite with comprehensive coverage!The test suite effectively covers:
- Success scenarios for owner operations
- Failure scenarios for unauthorized access
- Input validation for contract addresses
- Batch operations for both success and failure cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (10)
test/solidity/Facets/DexManagerFacet.t.sol (5)
50-58
: Consider adding negative assertions.While the test verifies successful DEX addition, it would be more robust to also assert that non-added DEXs are not accidentally approved.
function test_SucceedsIfOwnerAddsDex() public { vm.startPrank(USER_DIAMOND_OWNER); dexMgr.addDex(address(c1)); address[] memory approved = dexMgr.approvedDexs(); assertEq(approved[0], address(c1)); + assertEq(approved.length, 1); + assertFalse(dexMgr.approvedDexs().contains(address(c2))); vm.stopPrank(); }
227-238
: Maintain consistent prank patterns.The test uses individual
prank
calls instead of thestartPrank
/stopPrank
pattern used in other tests. This inconsistency makes the code harder to maintain.function testRevert_FailsIfNonOwnerTriesToRemoveDex() public { - vm.prank(USER_DIAMOND_OWNER); + vm.startPrank(USER_DIAMOND_OWNER); dexMgr.addDex(address(c1)); - vm.stopPrank(); + vm.stopPrank(); + vm.startPrank(NOT_DIAMOND_OWNER); vm.expectRevert(UnAuthorized.selector); - vm.prank(NOT_DIAMOND_OWNER); dexMgr.removeDex(address(c1)); + vm.stopPrank(); }
241-252
: Apply consistent prank pattern here as well.Similar to the previous test, this one should follow the same
startPrank
/stopPrank
pattern.function testRevert_FailsIfNonOwnerTriesToBatchRemoveDex() public { address[] memory dexs = new address[](2); dexs[0] = address(c1); dexs[1] = address(c2); - vm.prank(USER_DIAMOND_OWNER); + vm.startPrank(USER_DIAMOND_OWNER); dexMgr.batchAddDex(dexs); + vm.stopPrank(); + vm.startPrank(NOT_DIAMOND_OWNER); vm.expectRevert(UnAuthorized.selector); - vm.prank(NOT_DIAMOND_OWNER); dexMgr.batchRemoveDex(dexs); + vm.stopPrank(); }
304-306
: Optimize gas usage in test loops.For consistency with other loops in the codebase and to optimize gas usage, consider using unchecked increment.
- for (uint256 i = 0; i < 3; i++) { + for (uint256 i = 0; i < 3;) { assertTrue(dexMgr.isFunctionApproved(signatures[i])); + unchecked { ++i; } }
309-311
: Apply the same gas optimization here.For consistency, apply the same unchecked increment pattern here.
- for (uint256 i = 0; i < 3; i++) { + for (uint256 i = 0; i < 3;) { assertFalse(dexMgr.isFunctionApproved(signatures[i])); + unchecked { ++i; } }test/solidity/Facets/AccessManagerFacet.t.sol (1)
170-191
: Consider parameterizing the test with different method selectors.The test could be enhanced by testing multiple different method selectors to ensure consistent behavior.
- function test_DifferentMethodSelectorReturnsFalse() public { + function test_DifferentMethodSelectorReturnsFalse(bytes4 differentSelector) public { + vm.assume(differentSelector != RestrictedContract.restrictedMethod.selector); vm.startPrank(USER_DIAMOND_OWNER); accessMgr.setCanExecute( RestrictedContract.restrictedMethod.selector, address(0xb33f), true ); vm.stopPrank(); bool canExecute = accessMgr.addressCanExecuteMethod( - bytes4(keccak256("anotherMethod()")), + differentSelector, address(0xb33f) ); assertEq( canExecute, false, "Different method selector should return false" ); }test/solidity/Facets/CBridge.t.sol (2)
306-328
: Consider parameterizing the contract address test.The test could be enhanced by testing multiple different invalid contract addresses.
- function testRevert_FailsWhenTriggerRefundTryingToCallDiffrentContractThanCBridgeRouter() + function testRevert_FailsWhenTriggerRefundTryingToCallDiffrentContractThanCBridgeRouter(address invalidContract) public { + vm.assume(invalidContract != CBRIDGE_ROUTER); vm.startPrank(USER_DIAMOND_OWNER); - address callTo = address(0xdeadbeef); + address callTo = invalidContract; bytes memory callData = abi.encodeWithSignature("someFunction()"); address assetAddress = ADDRESS_USDT;
330-352
: Consider testing with different failure scenarios.The test could be enhanced by testing different types of external call failures.
function testRevert_FailsWhenTriggerRefundCallToCBridgeRouterFails() public { vm.startPrank(USER_DIAMOND_OWNER); address callTo = CBRIDGE_ROUTER; - bytes memory callData = abi.encodeWithSignature("someFunction()"); + bytes[] memory failureCases = new bytes[](3); + failureCases[0] = abi.encodeWithSignature("nonexistentFunction()"); + failureCases[1] = abi.encodeWithSignature("revertingFunction()"); + failureCases[2] = abi.encodeWithSignature("outOfGasFunction()"); + + for(uint i = 0; i < failureCases.length; i++) { + vm.expectRevert(ExternalCallFailed.selector); + cBridge.triggerRefund( + payable(callTo), + failureCases[i], + assetAddress, + to, + amount + ); + }test/solidity/Facets/DeBridgeDlnFacet.t.sol (1)
422-476
: Consider adding edge cases to the chain ID tests.While the test covers main scenarios, consider adding edge cases:
- Maximum possible domain ID
- Domain ID 0
- Sequential domain IDs
function test_CanGetChainIdForValidDomains() public { - DomainChainTestCase[] memory testCases = new DomainChainTestCase[](8); + DomainChainTestCase[] memory testCases = new DomainChainTestCase[](11); // ... existing test cases ... + testCases[8] = DomainChainTestCase({ + domainId: type(uint32).max, + expectedChainId: 0, + description: "Max domain ID should return 0" + }); + testCases[9] = DomainChainTestCase({ + domainId: 0, + expectedChainId: 0, + description: "Domain ID 0 should return 0" + }); + testCases[10] = DomainChainTestCase({ + domainId: 1, + expectedChainId: 0, + description: "Sequential domain ID should return 0" + });test/solidity/Facets/AmarokFacetPacked.t.sol (1)
422-476
: Consider parameterizing the domain ID test.The test could be enhanced by using property-based testing for domain IDs.
- function test_CanGetChainIdForValidDomains() public { + function test_CanGetChainIdForValidDomains(uint32 domainId) public { + vm.assume(domainId > 0); + + // Create mapping of known domain IDs to chain IDs + uint32[2][] memory knownMappings = new uint32[2][](7); + knownMappings[0] = [uint32(6648936), uint32(1)]; // ETH + knownMappings[1] = [uint32(1886350457), uint32(137)]; // POL + // ... add other mappings ... + + bool isKnown = false; + uint32 expectedChainId = 0; + + // Check if the domain ID is known + for(uint i = 0; i < knownMappings.length; i++) { + if(knownMappings[i][0] == domainId) { + isKnown = true; + expectedChainId = knownMappings[i][1]; + break; + } + } + + uint32 result = amarokFacetPacked.getChainIdForDomain(domainId); + + if(isKnown) { + assertEq(result, expectedChainId, "Known domain ID returned wrong chain ID"); + } else { + assertEq(result, 0, "Unknown domain ID should return 0"); + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
test/solidity/Facets/AccessManagerFacet.t.sol
(4 hunks)test/solidity/Facets/AmarokFacetPacked.t.sol
(3 hunks)test/solidity/Facets/CBridge.t.sol
(4 hunks)test/solidity/Facets/DeBridgeDlnFacet.t.sol
(4 hunks)test/solidity/Facets/DexManagerFacet.t.sol
(5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: run-unit-tests
- GitHub Check: enforce-min-test-coverage
🔇 Additional comments (7)
test/solidity/Facets/DexManagerFacet.t.sol (1)
1-315
: Overall test coverage looks comprehensive!The test file provides thorough coverage of the DexManagerFacet functionality, including:
- Authorization checks for owner/non-owner operations
- Input validation for addresses and contracts
- Both single and batch operations
- Function signature approval management
The suggested improvements are minor and focus on consistency and optimization.
test/solidity/Facets/AccessManagerFacet.t.sol (2)
117-124
: LGTM! Test verifies default access state.The test correctly checks that access is denied by default, which is a crucial security aspect.
126-144
: LGTM! Test verifies access granting functionality.The test properly validates that access can be granted and checked.
test/solidity/Facets/CBridge.t.sol (1)
206-243
: LGTM! Comprehensive test for refund with explicit receiver.The test properly validates:
- Balance changes using modifier
- Event emission
- Contract state changes
- External call mocking
test/solidity/Facets/DeBridgeDlnFacet.t.sol (1)
416-420
: LGTM! Well-structured test case definition.The struct provides a clear and maintainable way to define test cases.
test/solidity/Facets/AmarokFacetPacked.t.sol (2)
416-420
: LGTM! Well-structured test case definition.The struct provides a clear and maintainable way to define test cases.
478-493
: LGTM! Proper overflow testing.The test correctly verifies that large relayer fees are handled properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (7)
test/solidity/Facets/DeBridgeDlnFacet.t.sol (2)
44-57
: Consider adding a constant for the function selectors array size.The magic number
7
in the array size initialization could be replaced with a constant for better maintainability.+ uint256 private constant FUNCTION_SELECTORS_COUNT = 7; - bytes4[] memory functionSelectors = new bytes4[](7); + bytes4[] memory functionSelectors = new bytes4[](FUNCTION_SELECTORS_COUNT);
411-459
: Consider adding edge case tests for chain ID values.While the current tests cover the main functionality, consider adding tests for:
- Maximum uint256 values
- Special chain IDs (e.g., 0, 1)
+ function test_CanSetSpecialChainIds() public { + vm.startPrank(USER_DIAMOND_OWNER); + + // Test with chain ID 0 + deBridgeDlnFacet.setDeBridgeChainId(0, 42); + assertEq(deBridgeDlnFacet.getDeBridgeChainId(0), 42); + + // Test with max uint256 + uint256 maxChainId = type(uint256).max; + deBridgeDlnFacet.setDeBridgeChainId(maxChainId, 42); + assertEq(deBridgeDlnFacet.getDeBridgeChainId(maxChainId), 42); + + vm.stopPrank(); + }test/solidity/Facets/DexManagerFacet.t.sol (5)
10-10
: Remove duplicate import ofOnlyContractOwner
.The error type
OnlyContractOwner
is imported twice in the same line.-import { InvalidContract, OnlyContractOwner, CannotAuthoriseSelf, UnAuthorized, OnlyContractOwner } from "lifi/Errors/GenericErrors.sol"; +import { InvalidContract, OnlyContractOwner, CannotAuthoriseSelf, UnAuthorized } from "lifi/Errors/GenericErrors.sol";
315-317
: Optimize loop increment for gas efficiency.For consistency with other similar loops in the file and gas optimization, consider using unchecked increment.
- for (uint256 i = 0; i < 3; i++) { + for (uint256 i = 0; i < 3;) { assertTrue(dexMgr.isFunctionApproved(signatures[i])); + unchecked { ++i; } }
320-322
: Optimize loop increment for gas efficiency.For consistency with other similar loops in the file and gas optimization, consider using unchecked increment.
- for (uint256 i = 0; i < 3; i++) { + for (uint256 i = 0; i < 3;) { assertFalse(dexMgr.isFunctionApproved(signatures[i])); + unchecked { ++i; } }
239-249
: Maintain consistent prank pattern.For consistency with other test functions, use
startPrank
/stopPrank
pair and maintain consistent order of operations.- vm.prank(USER_DIAMOND_OWNER); + vm.startPrank(USER_DIAMOND_OWNER); dexMgr.addDex(address(c1)); + vm.stopPrank(); - vm.stopPrank(); + vm.startPrank(NOT_DIAMOND_OWNER); vm.expectRevert(UnAuthorized.selector); - vm.prank(NOT_DIAMOND_OWNER); dexMgr.removeDex(address(c1)); + vm.stopPrank();
256-262
: Maintain consistent prank pattern.For consistency with other test functions, use
startPrank
/stopPrank
pair.- vm.prank(USER_DIAMOND_OWNER); + vm.startPrank(USER_DIAMOND_OWNER); dexMgr.batchAddDex(dexs); + vm.stopPrank(); + vm.startPrank(NOT_DIAMOND_OWNER); vm.expectRevert(UnAuthorized.selector); - vm.prank(NOT_DIAMOND_OWNER); dexMgr.batchRemoveDex(dexs); + vm.stopPrank();
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
test/solidity/Facets/DeBridgeDlnFacet.t.sol
(4 hunks)test/solidity/Facets/DexManagerFacet.t.sol
(6 hunks)
🧰 Additional context used
🧠 Learnings (1)
test/solidity/Facets/DeBridgeDlnFacet.t.sol (1)
Learnt from: mirooon
PR: lifinance/contracts#975
File: test/solidity/Facets/DeBridgeDlnFacet.t.sol:0-0
Timestamp: 2025-02-17T07:59:54.979Z
Learning: In DeBridgeDlnFacet, chain ID mappings are hardcoded and not designed to be dynamically updated, so tests for mapping updates are not needed.
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: enforce-min-test-coverage
- GitHub Check: run-unit-tests
- GitHub Check: generate-tag
🔇 Additional comments (4)
test/solidity/Facets/DeBridgeDlnFacet.t.sol (3)
8-8
: LGTM! Well-structured error and event declarations.The new imports and declarations are well-organized and follow Solidity best practices.
Also applies to: 34-37
349-409
: LGTM! Comprehensive chain ID management tests.The test functions thoroughly validate:
- Setting chain IDs by the owner
- Access control restrictions
- Initialization requirements
- Retrieval functionality
440-459
: LGTM! Well-implemented storage test.The test effectively validates the storage layout using low-level storage access.
test/solidity/Facets/DexManagerFacet.t.sol (1)
290-384
: Great test coverage!The test suite provides comprehensive coverage of both positive and negative cases, including:
- Owner and non-owner access control
- Single and batch operations
- Function approval management
- Whitelisted address functionality
Which Jira task belongs to this PR?
Why did I implement it this way?
Checklist before requesting a review
Checklist for reviewer (DO NOT DEPLOY and contracts BEFORE CHECKING THIS!!!)